package com.sugar.follow.up.module.business.controller.admin.questionnairetemplatequestion;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.follow.up.framework.common.pojo.PageParam;
import com.sugar.follow.up.framework.common.pojo.PageResult;
import com.sugar.follow.up.framework.common.pojo.CommonResult;
import com.sugar.follow.up.framework.common.util.object.BeanUtils;
import static com.sugar.follow.up.framework.common.pojo.CommonResult.success;

import com.sugar.follow.up.framework.excel.core.util.ExcelUtils;

import com.sugar.follow.up.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.follow.up.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.follow.up.module.business.controller.admin.questionnairetemplatequestion.vo.*;
import com.sugar.follow.up.module.business.dal.dataobject.questionnairetemplatequestion.QuestionnaireTemplateQuestionDO;
import com.sugar.follow.up.module.business.service.questionnairetemplatequestion.QuestionnaireTemplateQuestionService;

@Tag(name = "管理后台 - 问卷模板题目")
@RestController
@RequestMapping("/business/questionnaire-template-question")
@Validated
public class QuestionnaireTemplateQuestionController {

    @Resource
    private QuestionnaireTemplateQuestionService questionnaireTemplateQuestionService;

    @PostMapping("/create")
    @Operation(summary = "创建问卷模板题目")
    @PreAuthorize("@ss.hasPermission('business:questionnaire-template:create')")
    public CommonResult<Long> createQuestionnaireTemplateQuestion(@Valid @RequestBody QuestionnaireTemplateQuestionSaveReqVO createReqVO) {
        return success(questionnaireTemplateQuestionService.createQuestionnaireTemplateQuestion(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新问卷模板题目")
    @PreAuthorize("@ss.hasPermission('business:questionnaire-template:update')")
    public CommonResult<Boolean> updateQuestionnaireTemplateQuestion(@Valid @RequestBody QuestionnaireTemplateQuestionSaveReqVO updateReqVO) {
        questionnaireTemplateQuestionService.updateQuestionnaireTemplateQuestion(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除问卷模板题目")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('business:questionnaire-template:delete')")
    public CommonResult<Boolean> deleteQuestionnaireTemplateQuestion(@RequestParam("id") Long id) {
        questionnaireTemplateQuestionService.deleteQuestionnaireTemplateQuestion(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除问卷模板题目")
                @PreAuthorize("@ss.hasPermission('business:questionnaire-template:delete')")
    public CommonResult<Boolean> deleteQuestionnaireTemplateQuestionList(@RequestParam("ids") List<Long> ids) {
        questionnaireTemplateQuestionService.deleteQuestionnaireTemplateQuestionListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得问卷模板题目")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('business:questionnaire-template:query')")
    public CommonResult<QuestionnaireTemplateQuestionRespVO> getQuestionnaireTemplateQuestion(@RequestParam("id") Long id) {
        QuestionnaireTemplateQuestionDO questionnaireTemplateQuestion = questionnaireTemplateQuestionService.getQuestionnaireTemplateQuestion(id);
        return success(BeanUtils.toBean(questionnaireTemplateQuestion, QuestionnaireTemplateQuestionRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得问卷模板题目分页")
    @PreAuthorize("@ss.hasPermission('business:questionnaire-template:query')")
    public CommonResult<PageResult<QuestionnaireTemplateQuestionRespVO>> getQuestionnaireTemplateQuestionPage(@Valid QuestionnaireTemplateQuestionPageReqVO pageReqVO) {
        PageResult<QuestionnaireTemplateQuestionDO> pageResult = questionnaireTemplateQuestionService.getQuestionnaireTemplateQuestionPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, QuestionnaireTemplateQuestionRespVO.class));
    }
}